package testLayer;

import static org.junit.Assert.*;
import modelLayer.Customer;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * This class is a JUnit test case of the Customer class.
 * 
 * @author A. Kelemen
 * @Version 1.1
 * 
 */

public class CustomerTest {
	
	private Customer customer;
	
	/**
	 * Initializes a test object.
	 * 
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		
		this.customer = new Customer(1, "Cecil Carlsen", "Tudevej 55", "Byen", "Landet","12345678", "cecil@cecilsen.dk", 1234);

	}

	@After
	public void tearDown() throws Exception {
	}
	
	/**
	 * Tests the constructor with parameters taking the parameters of the test object.
	 */
	@Test
	public void testCustomerWithParameters() {
		
		assertTrue(this.customer != null);
		
	}
	
	/**
	 * Tests the empty constructor without parameters. Initializes a new person object.
	 */
	@Test
	public void testCustomer() {
		
		this.customer = new Customer();
		assertTrue(this.customer != null);
		
	}
	
	/**
	 * Tests the constructor with an incorrect integer value. 
	 * This test method expects an exception and asserts true if an exception has been thrown.
	 */
	@Test (expected = IllegalArgumentException.class)
	public void testCustomerThrowsExceptionWrongID() {
		
		this.customer = new Customer( -1, "Cecil Carlsen", "Tudevej 55", "Byen", "Landet","12345678", "cecil@cecilsen.dk", 1234);

	}
	
	/**
	 * Tests the constructor with an incorrect String value. 
	 * This test method expects an exception and asserts true if an exception has been thrown.
	 */
	@Test (expected = IllegalArgumentException.class)
	public void testCustomerThrowsExceptionWrongString() {
		
		this.customer = new Customer( -1, "Cecil Carlsen", " ", "Byen", "Landet"," ", "cecil@cecilsen.dk", 1234);

	}
	
	/**
	 * Tests the constructor with incorrect integer value.
	 * The test method catches the exception and prints it on the console.
	 */
	@Test 
	public void testCustomerThrowsExceptionWrongIDMessage() {
		try {
			this.customer = new Customer( -1, "Cecil Carlsen", "Tudevej 55", "Byen", "Landet","12345678", "cecil@cecilsen.dk", 1234);
		}
		catch (IllegalArgumentException e) {
			System.out.println(e.getMessage());
		}
		
	}
	
	/**
	 * Tests the constructor with incorrect String value.
	 * The test method catches the exception and prints it on the console.
	 */
	@Test 
	public void testCustomerThrowsExceptionWrongStringMessage() {
		try {
			this.customer = new Customer( -1, "Cecil Carlsen", " ", "Byen", "Landet"," ", "cecil@cecilsen.dk", 1234);
		}
		catch (IllegalArgumentException e) {
			System.out.println(e.getMessage());
		}
		
	}
	
	/**
	 * Tests if the value of the getCustomerID() method equals the expected customerID value of the test object.
	 */
	@Test
	public void testGetCustomerID() {
		
		assertEquals(1, this.customer.getCustomerID());
		
	}

}
